﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FF.Method;

namespace FF
{
    public partial class FormGoodSelect : Form
    {
        public const int FORM_TYPE_FormSale = 1;
        public const int FORM_TYPE_FormCancleSale = 2;
        private int formType;
        public FormGoodSelect(int formtype)
        {
            InitializeComponent();
            this.formType = formtype;
        }

        private void FormGoodSelect_Load(object sender, EventArgs e)
        {
            GoodMethod.fillGood(this.treeView1, imageList1);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.Level != 1)
            {
                MessageBox.Show("请选择");
                return;
            }
            else if (treeView1.SelectedNode.Level == 1)
            {
                switch (this.formType)
                {
                    case FormGoodSelect.FORM_TYPE_FormSale:
                        FormSale frm = (FormSale)this.Owner;

                        frm.textBoxGoodID.Text = treeView1.SelectedNode.Name;
                        string nameprice = treeView1.SelectedNode.Text;
                        string[] array = nameprice.Split('|');
                        frm.textBoxGoodName.Text = array[0];
                        frm.textBoxPrice.Text = array[1];
                        // frm.textBoxGoodName.Text = treeView1.SelectedNode.Text;

                        //frm.textBoxPrice.Text = GoodMethod.getGoodById(treeView1.SelectedNode.Name).price;
                        //frm.userName = treeView1.SelectedNode.Text;
                        this.Close();
                        break;
                    case FormGoodSelect.FORM_TYPE_FormCancleSale:
                        FormCancleSale frm1 = (FormCancleSale)this.Owner;
                        frm1.textBoxGoodID.Text = treeView1.SelectedNode.Name;
                        string nameprice1 = treeView1.SelectedNode.Text;
                        string[] array1 = nameprice1.Split('|');
                        frm1.textBoxGoodName.Text = array1[0];
                        frm1.textBoxPrice.Text = array1[1];
                        // frm.textBoxGoodName.Text = treeView1.SelectedNode.Text;

                        //frm.textBoxPrice.Text = GoodMethod.getGoodById(treeView1.SelectedNode.Name).price;
                        //frm.userName = treeView1.SelectedNode.Text;
                        this.Close();
                        break;
                }
            }
        }

        private void treeView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {

        }

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            buttonOK_Click(sender, e);
        }
    }
}
